<?php

namespace app\services;

class UserService
{
	public function checkLogin()
	{
		$skips = ["register", "login", "test"];

		$route = \Route::getRoute();

		if(!in_array($route->method, $skips)) {
			if(empty($_COOKIE['access_token'])) {
				$url = rtrim($route->index, '/') . "/user/login";
				//redirect($url);
			}
		}
	}
	
	public function login($data)
	{

	}

	public function logout()
	{
		setcookie("access_token", null, time()-3600);
		session_destroy();
		redirect(\Route::getIndex());
	}

	public function userInfo($uid)
	{
		if(!is_numeric($uid) || $uid < 1){
			return ["uid" => 0, "name" => "User not exist"];
		}
		return ["uid" => $uid, "name" => "test_".$uid];
	}
}